package com.ehome.poct.base.controller.device;

import com.ehome.core.util.BeanConvertUtil;
import com.ehome.poct.base.api.dto.device.DeviceVersionReqDTO;
import com.ehome.poct.base.api.dto.device.SoftwareUpgradeQry;
import com.ehome.poct.base.api.dto.device.TestDeviceVersionDTO;
import com.ehome.poct.base.api.dto.device.VersionStatusQry;
import com.ehome.poct.base.api.virtual.TestDeviceVersionService;
import com.ehome.poct.base.api.vo.device.TestDeviceVersionVO;
import com.ehome.web.controller.AbstractBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 版本表控制器
 *
 * @author yjm
 * @Date 2021-12-06 16:53
 */
@Slf4j
@Api(tags = "版本表")
@RestController
@RequestMapping("/test_device_version")
public class TestDeviceVersionController extends AbstractBaseController<TestDeviceVersionVO, TestDeviceVersionDTO> {
    
    @Autowired
    private TestDeviceVersionService testDeviceVersionService;
    
    @ApiOperation("发布版本信息(添加到DB,发布到订阅主题上)")
    @PostMapping("/pubVersion")
    public void pubVersion(@RequestBody DeviceVersionReqDTO reqDto) {
        testDeviceVersionService.sendmqtt(reqDto);
    }

    @ApiOperation("修改版本状态")
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestBody VersionStatusQry qry){
        testDeviceVersionService.editStatus(qry);
    }

    @ApiOperation("获取最新的版本信息")
    @GetMapping("/new_version")
    public List<TestDeviceVersionVO> getNewVersion(TestDeviceVersionDTO dto){
        return BeanConvertUtil.convertBeanList(testDeviceVersionService.getNewVersion(dto),TestDeviceVersionVO.class);
    }

    @ApiOperation("根据版本信息获取版本数据")
    @PostMapping("/software_upgrade")
    public List<TestDeviceVersionDTO> getSoftwareUpgradeInfo(@RequestBody SoftwareUpgradeQry qry){
        List<TestDeviceVersionDTO> list = testDeviceVersionService.getSoftwareUpgradeInfo(qry);
        return list;
    }
}
